package cn.chinaiptv.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;

public class PlatPropertyUtils {
	/**
	 * getAddress方法，通过传入不同平台的名称，来获取不同平台的地址并返回
	 * 
	 * @param platformName
	 * @return
	 */
	public static String getAddress(String platformName) {
		HashMap<String, String> platforms = getplatform("platform.properties");
		if (platforms.size() == 0) {
			return "";
		} else {
			return platforms.get(platformName);
		}
	}

	/**
	 * 读取关于华为和中兴平台地址的配置文件，对相关地址进行解析，存放到map集合中并返回
	 * 
	 * @param filename
	 * @return
	 */
	public static HashMap<String, String> getplatform(String filename) {
		HashMap<String, String> platforms = new HashMap<String, String>();
		InputStream in = PlatPropertyUtils.class.getClassLoader()
				.getResourceAsStream(filename);
		Properties properties = new Properties();
		try {
			properties.load(in);
			properties.keys();
			Iterator<String> it = properties.stringPropertyNames().iterator();
			while (it.hasNext()) {
				String key = it.next();
				platforms.put((key), properties.getProperty(key));
			}
			return platforms;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
